<template>
  <div class="content">
    <img src="../../../../assets/images/nav.png" class="navimg" />
    <div class="tabs">
      <ul class="tab-buttons">
        <li @click="currentTab = 1" :class="{ active: currentTab === 1 }">
          <i class="el-icon-user"></i>个人资料
        </li>
        <li @click="currentTab = 2" :class="{ active: currentTab === 2 }">
          <i class="el-icon-lock"></i>密码安全
        </li>
      </ul>
      <div class="tab-content">
        <div v-show="currentTab === 1">
          <el-form ref="form" :model="form" label-width="100px">
            <el-row>
              <el-col :span="12">
                <el-form-item label="姓名" prop="ksName">
                  <el-input
                    v-model="form.ksName"
                    placeholder="请输入姓名"
                    disabled
                  />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="性别" prop="sexName">
                  <el-input
                    v-model="form.sexName"
                    placeholder="请输入性别"
                    disabled
                  />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="民族" prop="nationName">
                  <el-input
                    v-model="form.nationName"
                    placeholder="请输入民族"
                    disabled
                  />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="出生年月" prop="birthDate">
                  <el-input
                    v-model="form.birthDate"
                    placeholder="请输入出生年月"
                    disabled
                  />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="籍贯" prop="nativePlace">
                  <el-input
                    v-model="form.nativePlace"
                    placeholder="请输入籍贯"
                    disabled
                  />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="出生地" prop="birthPlace">
                  <el-input
                    v-model="form.birthPlace"
                    placeholder="请输入出生地"
                    disabled
                  />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="政治面貌" prop="politicalStatus">
                  <el-input
                    v-model="form.politicalStatus"
                    placeholder="请输入政治面貌"
                    disabled
                  />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="身份证号码" prop="cardNumber">
                  <el-input
                    v-model="form.cardNumber"
                    placeholder="请输入身份证号码"
                    disabled
                  />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="联系电话" prop="phonenumber">
                  <el-input
                    v-model="form.phonenumber"
                    placeholder="请输入联系电话"
                    disabled
                  />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="应聘方向" prop="ksSpecialtyName">
                  <el-input
                    v-model="form.ksSpecialtyName"
                    placeholder="请输入应聘方向"
                    disabled
                  />
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </div>
        <div v-show="currentTab === 2">
           <el-form ref="passwordform" :model="user" :rules="rules" label-width="80px">
            <el-form-item label="新密码" prop="password">
              <el-input
                v-model="user.password"
                placeholder="请输入新密码"
                type="password"
                show-password
              />
            </el-form-item>
            <el-form-item label="确认密码" prop="confirmPassword">
              <el-input
                v-model="user.confirmPassword"
                placeholder="请确认密码"
                type="password"
                show-password
              />
            </el-form-item>
            <el-form-item>
              <el-button type="primary" size="mini" @click="submit"
                >确认修改</el-button
              >
            </el-form-item>
          </el-form>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Cookies from "js-cookie";
import { getksUsernews,updateUserPwd } from "@/api/whpx/ksUser";
export default {
  data() {
    const equalToPassword = (rule, value, callback) => {
      if (this.user.password !== value) {
        callback(new Error("两次输入的密码不一致"));
      } else {
        callback();
      }
    };
    return {
      currentTab: 1,
      form: {},
      test: "1test",
      user: {
        id:undefined,
        password: undefined,
        confirmPassword: undefined
      },
      // 表单校验
      rules: {
        password: [
          { required: true, message: "新密码不能为空", trigger: "blur" },
          { min: 6, max: 20, message: "长度在 6 到 20 个字符", trigger: "blur" }
        ],
        confirmPassword: [
          { required: true, message: "确认密码不能为空", trigger: "blur" },
          { required: true, validator: equalToPassword, trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getinfo();
  },
  methods: {
    getinfo() {
      var useid = Cookies.get("id");
      getksUsernews(useid).then(res => {
        this.form = res.data;
      });
    },
    submit() {
      this.$refs["passwordform"].validate(valid => {
        if (valid) {
          this.user.id = Cookies.get("id")
          updateUserPwd(this.user).then(
            () => {
              this.msgSuccess("修改成功");
              this.user = {}
            }
          );
        }
      });
    },
  }
};
</script>

<style lang="scss" scoped>
.content {
  width: 100%;
  padding: 0.2rem;
  box-sizing: border-box;
  background: #fff;
}
.navimg {
  width: 100%;
}
.tabs {
  width: 100%;
  margin-top: 20px;
  display: flex;
  height: 600px;
  .tab-buttons {
    width: 200px;
    background: #f8f8f8;
    li {
      height: 45px;
      line-height: 45px;
      font-size: 14px;
      color: #303133;
      padding: 0 20px;
      cursor: pointer;
      i {
        font-size: 16px;
        padding-right: 10px;
      }
    }
  }
  .tab-buttons li:hover {
    background: #ccc;
  }
  .tab-content {
    flex: 1;
    border: 1px solid #f1f1f1;
    padding: 20px;
    box-sizing: border-box;
  }
}
.active {
  color: #1890ff !important;
}
</style>
